package com.hongyuan.sellfitness.ui.find.activity;

import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityCireclePeopleBinding;
import com.hongyuan.sellfitness.ui.find.view_mode.CirclePeopleViewModel;
import com.hongyuan.sellfitness.utils.CustomDialog;

import me.tatarka.bindingcollectionadapter2.BR;

public class CirclePeopleActivity extends CustomActivity<ActivityCireclePeopleBinding, CirclePeopleViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_cirecle_people;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public CirclePeopleViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CirclePeopleViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();
        setOnRefresh(binding.refresh,REFRESH_0X3);

        setEnableLoadMore(Constants.GET_CIRCLE_MEMBER_LIST);
        setEnableRefresh(Constants.GET_CIRCLE_MEMBER_LIST);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("circle_categoryid",getBundle().getString("circle_categoryid"));
        viewModel.requestData(Constants.GET_CIRCLE_MEMBER_LIST);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

        viewModel.uc.showCancel.observe(this, aVoid -> {
            CustomDialog.promptDialog(this, "确定要取消关注吗？", "确定", "取消", false, v1 -> {
                if (v1.getId() == R.id.isOk) {
                    viewModel.requestData(Constants.ADD_FRIENT);
                }
            });
        });
    }
}
